//清除点名数据
function deleted(id) {
	$.get("delete?uid=" + id, function() {
		$('#dgg').datagrid('reload');
	});
}
// 奖励
function good(id) {
	$.get("good?uid=" + id, function() {
		$('#dgg').datagrid('reload');
	});
}
// 批评
function bad(id) {
	$.get("bad?uid=" + id, function() {
		$('#dgg').datagrid('reload');
	});
}
// 旷课
function truant(id) {
	$.get("truant?uid=" + id, function() {
		$('#dgg').datagrid('reload');
	});
}
// 迟到
function late(id) {
	$.get("late?uid=" + id, function() {
		$('#dgg').datagrid('reload');
	});
}
// 病假
function sick(id) {
	$.get("sick?uid=" + id, function() {
		$('#dgg').datagrid('reload');
	});
}
// 事假
function holiday(id) {
	$.get("holiday?uid=" + id, function() {
		$('#dgg').datagrid('reload');
	});
}


// 清除所有学生数据
function deleteall() {
	var pwd = $("#pwd").val();
	if (pwd == "admin") {
		$('#windeleteAll').window('close');
		$.get("deleteAll");
		$('#dgg').datagrid('reload');
	} else {
		$.messager.alert('清除所有学生数据', '清除密码错误!', 'error');
	}
}
function deleteold() {
	var pwd = $("#pwd1").val();
	if (pwd == "admin") {
		$('#windeleteOld').window('close');
		$.get("deleteOld");
		$('#dgg').datagrid('reload');
	} else {
		$.messager.alert('清除所有学生数据', '清除密码错误!', 'error');
	}
}
// 导入学生数据
function ImportExcel() {
	var formData = new FormData($("#ff")[0]);
	$.ajax({
		url : "upload_json",
		type : "POST",
		data : formData,
		async : false,
		cache : false,
		contentType : false,
		processData : false,
		success : function(data) {
			$('#winimportt').window('close');
			$.messager.show({
				title : '导入学生数据',
				msg : '上传成功',
				showType : 'show'
			});
			var obj = document.getElementById('attach') ;
			obj.outerHTML=obj.outerHTML; 
			$('#dgg').datagrid('reload');
		},
		error : function() {
			$('#winimportt').window('close');
			$.messager.alert('导入学生数据', '导入失败', 'error');
		}
	});
}

// 上传本节课任务书
function uploadMaterial() {
	var attachs = new FormData($("#scrws")[0]);
	// var attachs=$("#attachs").val();
	$.ajax({
		url : "uploadMaterial",
		type : "POST",
		data : attachs,
		async : false,
		cache : false,
		contentType : false,
		processData : false,
		success : function(data) {
			$('#winupload').window('close');
			$.messager.show({
				title : '上传本节课任务书',
				msg : '上传成功',
				showType : 'show'
			});
			var obj = document.getElementById('attachs') ;
			obj.outerHTML=obj.outerHTML; 
			$('#ren').datagrid('reload');
		},
		error : function() {
			$('#winupload').window('close');
			$.messager.alert('上传本节课任务书', '上传失败', 'error');
		}
	});
}
// 刷新
function sx() {
	$('#dgg').datagrid('reload');
}
function updateTotal() {
	$.getJSON("getCount.do", function(json) {
		var data = $('#dgg').datagrid('getData');
		document.getElementById("zrs").innerHTML = data.total;
		document.getElementById("yd").innerHTML = json.arrive;
		document.getElementById("yjzy").innerHTML = json.work;
		getUrl();
	});
}

function getUrl() {
		$.getJSON("getUrl.do", function(json) {	
			$("#myLayOut").layout('panel','south').panel('setTitle','<h4 style="float:left;">版权所有</h4><h2 style="float:left;margin-left:50%;">登录地址&nbsp;&nbsp;<span style="font-family: \'微软雅黑,楷体\';color:red;">'+json.url+'</span></h2>');

		//document.getElementById("url").innerHTML = json.url;
	});
}

function format_meterial_btn(value, row, index) {
	var cz = '<a href="javascript:delmaterial(' + "'" + row.id + "'"
			+ ')">删除</a>';
	return cz;
}

function downloadMaterial(value){
	$.get("download.do",{id:value}, function(result) {
		var data =  $.parseJSON(result);
		window.location.href = "downloadByIo?url="+data.msg;
	});
}

function downloadHomeWork(value){
	$.get("downloadHomeWork.do",{id:value}, function(result) {
		var data =  $.parseJSON(result);
		window.location.href = encodeURI(data.msg);
	});
}

function xiazaiMaterial(value, row, index) {
	var cz = '<a href="javascript:downloadMaterial(\''+row.id+'\')">'+value+'</a>'

	return cz;
}

// 执行任务书删除功能
function delmaterial(id) {
	$.messager.confirm('确认', '您确认想要删除记录吗？', function(r) {
		if (r) {
			$.get("delMeterial", {
				id : id
			}, function() {
				$('#ren').datagrid('reload');
			});
		}
	});
}

function formathomework(value, row, index) {
	if (value != null && value != undefined && value !== '') {
		return '已交';
	}
}
function formatkao(value, row, index) {
	if (value ==='C') {
		return '<img src="img/late.png"/>';
	}
	if (value ==='K'){
		return '<img src="img/truant.png"/>';
	}
	if (value ==='B'){
		return '<img src="img/sick.png"/>';
	}
	if (value ==='S'){
		return '<img src="img/holiday.png"/>';
	}
	return value;
}
function formatgood(value, row, index) {
	if (value == null)
		value = 0;
	var cz = '<a href="javascript:good('
			+ row.uid
			+ ')"><img src="img/good.gif" style="display:inline-block;vertical-align:middle;"/></a>'
			+ '<p style="display:inline-block;width:30px;text-align: center;">'
			+ value
			+ '</p>'
			+ '<a href="javascript:bad('
			+ row.uid
			+ ')"><img src="img/bad.gif" style="display:inline-block;vertical-align:middle;"/></a>'
	return cz;
}
function formatcontrol(value, row, index) {
	var cz = '<a href="javascript:truant('
			+ row.uid
			+ ')" style="display:inline-block; width:30px;text-align: center;margin:0 5px;">旷课</a>'
			+ '<a href="javascript:late('
			+ row.uid
			+ ')" style="display:inline-block; width:30px;text-align: center;margin:0 5px;">迟到</a>'
			+ '<a href="javascript:sick('
			+ row.uid
			+ ')" style="display:inline-block; width:30px;text-align: center;margin:0 5px;">病假</a>'
			+ '<a href="javascript:holiday('
			+ row.uid
			+ ')" style="display:inline-block; width:30px;text-align: center;margin:0 5px;">事假</a>'
			+ '<a href="javascript:deleted('
			+ row.uid
			+ ')" style="display:inline-block; width:30px;text-align: center;margin:0 5px;">清除</a>'
	return cz;
}
